package sanrenxing.dayEnd.backRepertoryTotal.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import sanrenxing.dayEnd.backRepertoryTotal.domain.TrusteeSetup;

import java.util.List;
import java.util.Map;

/**
 * 功能：托管人数据层实体类
 * 编写者：蒋玲苹
 * 日期：
 * 版本：1.0
 */
@Repository
public interface TrusteeSetupDao {
    /**
     * 添加数据
     * @param trusteeSetup
     * @return 0:添加失败,1:添加成功
     */
    @Insert("insert into trusteeSetup values(seqTrusteeSetup.nextval,#{company},#{comAddress},#{phone},#{custoName},#{custoRate})")
    public int add(TrusteeSetup trusteeSetup);

    /**
     * 删除数据
     * @param custoId
     * @return
     */
    @Delete("delete from trusteeSetup where custoId=#{custoId}")
    public int delete(@Param("custoId") int custoId);

    /**
     * 修改数据
     * @param trusteeSetup
     * @return
     */
    @Update("update trusteeSetup set company=#{company},comAddress=#{comAddress},phone=#{phone},custoName=#{custoName},custoRate=#{custoRate} where custoId=#{custoId}")
    public int update(TrusteeSetup trusteeSetup);

    /**
     * 查询所有数据
     * @param map
     * @return
     */
    @Select("<script>" +
            "select * from " +
            " (select rownum rn,trusteeSetup.* from trusteeSetup " +
            " <where>#{end}>=rownum</where>)" +
            "<where>" +
            "<if test='trusteeSetup.custoName!=null'>" +
            " and custoName like '%${trusteeSetup.custoName}%'" +
            "</if>" +
            "<if test='trusteeSetup.company!=null'>" +
            " and company like '%${trusteeSetup.company}%'" +
            "</if>" +
            " and rn>=#{start}" +
            "</where>" +
            "</script>")
    public List<TrusteeSetup>  queryAll(Map<String, Object> map);

    /**
     * 统计记录数
     * @param
     * @return 记录行数据
     */
    @Select("select count(*) from trusteeSetup")
    public int count();

}
